package com.ljb.baseadapter_demo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.ljb.baseadapter_listview.CommonAdapter;
import com.ljb.baseadapter_listview.ViewHolder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ListViewActivity extends AppCompatActivity {

    private List<String> mDatas = new ArrayList<>(Arrays.asList("MultiItem ListView", "RecyclerView", "MultiItem RecyclerView"));

    private ListView listview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);

        //单一类型条目的ListView使用方法
        listview = (ListView) findViewById(R.id.lv);
        listview.setAdapter(new CommonAdapter<String>(this, R.layout.item_listview, mDatas) {
            @Override
            public void convert(ViewHolder holder, String item, int position) {
                holder.setText(R.id.tv, item);
            }
        });
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                Intent intent = null;
                switch (position) {
                    case 0:
                        intent = new Intent(ListViewActivity.this, MultiItemListViewActivity.class);
                        break;
                    case 1:
                        intent = new Intent(ListViewActivity.this, RecyclerViewActivity.class);
                        break;
                    case 2:
                        intent = new Intent(ListViewActivity.this, MultiItemRVActivity.class);

                        break;
                }
                if (intent != null)
                    startActivity(intent);
            }
        });

    }
}
